package org.csu.mypetstore.persistence;

//this is completed
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.mypetstore.domain.Category;
import org.csu.mypetstore.domain.Item;
import org.csu.mypetstore.domain.Product;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface CategoryMapper extends BaseMapper<Category> {
    //查询所有的商品
    @Select("SELECT\n" +
            "              CATID AS categoryId,\n" +
            "              NAME,\n" +
            "              DESCN AS description\n" +
            "            FROM CATEGORY")
    List<Category> getCategoryList();

    //通过id查询某一商品
    @Select("SELECT CATID AS categoryId,NAME, DESCN AS description FROM CATEGORY WHERE CATID = #{categoryId};")
    Category getCategory(String categoryId);

    @Delete(" DELETE FROM CATEGORY WHERE catid = #{itemId};")
    void deleteCastegory(String itemId);

    @Insert("INSERT INTO CATEGORY VALUES (#{categoryId},#{name},#{description});")
    void insertCategory(Category category);

    @Select("SELECT\n" +
            "              CATID AS categoryId,\n" +
            "              NAME,\n" +
            "              DESCN AS description\n" +
            "            FROM CATEGORY WHERE catid like #{keyword};")
    List<Category>searchCategory(String keyword);
    @Update("UPDATE CATEGORY SET catid = #{categoryId}, name = #{name},descn = #{description} WHERE catid = #{categoryId};")
    void updateCategory(Category category);
}
